﻿using Masuit.Tools.Models;
using Prism.Mvvm;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AJWPFAdmin.Core.Components.AJTable.ViewModels
{
    public class AJTableFetchOptions : BindableBase
    {
        /// <summary>
        /// 是否控件一加载就调用 Handle
        /// </summary>
        public bool FetchOnLoaded
        {
            get; set;
        } = true;

        private Views.AJTable _component;
        /// <summary>
        /// 组件本身实例，组件初始化后会自动赋值， 其他地方请不要操作赋值
        /// </summary>
        public Views.AJTable Component
        {
            set
            {
                _component = value;
            }
        }

        private Func<AJTableSearchFormConfig, AJTablePagination, Task<AJTableFetchResult>> _handle;
        public Func<AJTableSearchFormConfig, AJTablePagination,Task<AJTableFetchResult>> Handle
        {
            get
            {
                return _handle;
            }
            set
            {
                SetProperty(ref _handle, value);
            }
        }

        /// <summary>
        /// 导出文件名称，不传默认 列表导出， 会自动加上 yyyyMMddHHmmss 日期
        /// </summary>
        public string ExportFileName { get; set; } = "列表导出";

        /// <summary>
        /// 导出时仅限定当前表格配置的列, 否则导出所有配置了 AJExportFieldAttribute 的实体属性
        /// </summary>
        public bool ExportWithCurrentColumns { get; set; }

        private bool _exportWithImage;
        /// <summary>
        /// 是否导出图片
        /// </summary>
        public bool ExportWithImage
        {
            get
            {
                return _exportWithImage;
            }
            set
            {
                SetProperty(ref _exportWithImage, value);
            }
        }

        public void RequestRefresh(bool reset = true)
        {
            _component?.Refresh(reset);
        }

        public void RequestExport()
        {
            _component?.ExecuteExport();
        }

    }
}
